package com.hottop.web.controller.system;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hottop.common.annotation.Log;
import com.hottop.common.core.controller.BaseController;
import com.hottop.common.core.domain.AjaxResult;
import com.hottop.common.enums.BusinessType;
import com.hottop.system.domain.TJinrihot;
import com.hottop.system.service.ITJinrihotService;
import com.hottop.common.utils.poi.ExcelUtil;
import com.hottop.common.core.page.TableDataInfo;

/**
 * 今日头条热搜Controller
 * 
 * @author ruoyi
 * @date 2022-02-19
 */
@RestController
@RequestMapping("/system/jinrihot")
public class TJinrihotController extends BaseController
{
    @Autowired
    private ITJinrihotService tJinrihotService;

    /**
     * 查询今日头条热搜列表
     */
    @PreAuthorize("@ss.hasPermi('system:jinrihot:list')")
    @GetMapping("/list")
    public TableDataInfo list(TJinrihot tJinrihot)
    {
        startPage();
//        if (tJinrihot.getMindate()!=null){
//            SimpleDateFormat df = new SimpleDateFormat("hh:mm");
//            String replace = tJinrihot.getMindate().toString().replace('-', ':');
//            Date date = null;
//            try {
//                date = df.parse(replace);
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//            tJinrihot.setMindate(date);
//        }
        List<TJinrihot> list = tJinrihotService.selectTJinrihotList(tJinrihot);
        return getDataTable(list);
    }

    /**
     * 导出今日头条热搜列表
     */
    @PreAuthorize("@ss.hasPermi('system:jinrihot:export')")
    @Log(title = "今日头条热搜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TJinrihot tJinrihot)
    {
        List<TJinrihot> list = tJinrihotService.selectTJinrihotList(tJinrihot);
        ExcelUtil<TJinrihot> util = new ExcelUtil<TJinrihot>(TJinrihot.class);
        util.exportExcel(response, list, "今日头条热搜数据");
    }

    /**
     * 获取今日头条热搜详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:jinrihot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tJinrihotService.selectTJinrihotById(id));
    }

    /**
     * 新增今日头条热搜
     */
    @PreAuthorize("@ss.hasPermi('system:jinrihot:add')")
    @Log(title = "今日头条热搜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TJinrihot tJinrihot)
    {
        return toAjax(tJinrihotService.insertTJinrihot(tJinrihot));
    }

    /**
     * 修改今日头条热搜
     */
    @PreAuthorize("@ss.hasPermi('system:jinrihot:edit')")
    @Log(title = "今日头条热搜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TJinrihot tJinrihot)
    {
        return toAjax(tJinrihotService.updateTJinrihot(tJinrihot));
    }

    /**
     * 删除今日头条热搜
     */
    @PreAuthorize("@ss.hasPermi('system:jinrihot:remove')")
    @Log(title = "今日头条热搜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tJinrihotService.deleteTJinrihotByIds(ids));
    }
}
